package com.rabbitmq.producer.config;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Author: Thomas
 * @Date: 2024-01-20  16:55:07
 * @Description:
 */
@Configuration
public class DirectRabbitMQConfig {

    // 1. 声明交换机fanout【创建交换机】
    @Bean
    public DirectExchange directExchange(){
        // 持久化 不自动删除
        return new DirectExchange("direct_order_exchange", true, false);
    }
    // 2. 声明队列 sms.fanout.queue  email.fanout.queue  message.fanout.queue 【创建队列】
    @Bean
    public Queue sms01(){
        return new Queue("sms.direct.queue", true);
    }
    @Bean
    public Queue email01(){
        return new Queue("email.direct.queue", true);
    }
    @Bean
    public Queue message01(){
        return new Queue("message.direct.queue", true);
    }
    // 3. 完成绑定关系
    @Bean
    public Binding sms01Binding(){
        // 通过with指定路由key
        return BindingBuilder.bind(sms01()).to(directExchange()).with("sms");
    }
    @Bean
    public Binding email01Binding(){
        return BindingBuilder.bind(email01()).to(directExchange()).with("email");
    }
    @Bean
    public Binding massge01Binding(){
        return BindingBuilder.bind(message01()).to(directExchange()).with("message");
    }

}
